home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / demos / audio / drive / Connect.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.3 KB  |  117 lines

  1. /*
  2.  * Copyright 1992-1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. //////////////////////////////////////////////////////////////////////
  18. // Connect.c++ - definition of the connect class
  19. //
  20. // This class defines a connect stretch of road. It is
  21. // derived from the stretch abstract base class.
  22. //////////////////////////////////////////////////////////////////////
  23.  
  24. #include <math.h>
  25. #include "Stretch.h"
  26. #include "Connect.h"
  27.  
  28. Connect::Connect(Stretch *prev, Stretch *next)
  29.     : Stretch(prev, next)
  30. {
  31.     if (!prev || !next)
  32.     {
  33.         fprintf(stderr,"Connect stretches must have a prev and a next\n");
  34.         exit(-1);
  35.     }
  36.  
  37.     _type = CONNECT;
  38.     _step = 30.0;
  39.     
  40.     _turn_angle = _turn_radius = 0.0; // straights do not curve
  41.     _hill_angle = _hill_radius = _bank_angle = 0.0;
  42.  
  43.     _length=
  44.         (_prev->get_middle(_prev->get_count()-1) 
  45.         - _next->get_middle(0)).length();
  46.         
  47.     _width = _prev->get_side_direction(_prev->get_count()-1,LEFT).length();
  48.         
  49.     Stretch::compute_step();
  50.     Stretch::allocate_data();
  51.  
  52.     // find the accumulated offset and orientation 
  53.     SbVec3f prev_offset;
  54.     SbRotation prev_orientation;
  55.     Stretch::find_previous(prev_offset, prev_orientation);
  56.  
  57.     make_connect(prev_orientation);
  58.  
  59.     Stretch::init_scenery();    
  60. }
  61.  
  62.  
  63. Connect::~Connect()
  64. {
  65. }
  66.  
  67.  
  68. void Connect::make_connect(SbRotation prev_orientation)
  69. {
  70.     for (int j = 0; j < _num_markers; j++)
  71.     {
  72.         float interp = (float)j/(float)(_num_markers - 1);
  73.         
  74.         _data[j].left =    
  75.             (1.0 - interp)*_prev->get_left(_prev->get_count()-1) +
  76.             interp* _next->get_left(0);
  77.         
  78.         _data[j].middle =    
  79.             (1.0 - interp)*_prev->get_middle(_prev->get_count()-1) +
  80.             interp* _next->get_middle(0);
  81.         
  82.         _data[j].right =    
  83.             (1.0 - interp)*_prev->get_right(_prev->get_count()-1) +
  84.             interp* _next->get_right(0);
  85.         
  86.         _data[j].normal =    
  87.             (1.0 - interp)*_prev->get_normal(_prev->get_count()-1) +
  88.             interp* _next->get_normal(0);
  89.         
  90.         // median
  91.         _median_data[j].left = 
  92.         _data[j].left + (1.0-STRIPE_WIDTH)*(_data[j].middle - _data[j].left);
  93.         
  94.         _median_data[j].right =
  95.         _data[j].middle + STRIPE_WIDTH*(_data[j].right - _data[j].middle);
  96.  
  97.         _median_data[j].left += STRIPE_HEIGHT*_data[j].normal;
  98.         _median_data[j].right += STRIPE_HEIGHT*_data[j].normal;
  99.                 
  100.         // terrain
  101.         _left_terrain_data[j].left = 
  102.         _data[j].left + TERRAIN_WIDTH*(_data[j].left - _data[j].middle);
  103.         _left_terrain_data[j].right = _data[j].left;
  104.         
  105.         _right_terrain_data[j].right =
  106.         _data[j].middle + TERRAIN_WIDTH*(_data[j].right - _data[j].middle);
  107.         _right_terrain_data[j].left = _data[j].right;
  108.     }
  109.  
  110.     // offset from origin to end of this stretch
  111.     _offset = _data[_num_markers-1].middle;
  112.  
  113.     SbRotation this_quat(_data[0].normal,_data[_num_markers - 1].normal);
  114.     _orientation = this_quat * prev_orientation;
  115. }
  116.  
  117.